home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Enigma Amiga Life 109
/
EnigmaAmiga109CD.iso
/
dalla rivista
/
amiga.free
/
sorgenti vari
/
wolfedit2 2.0.4 source.sit
/
WolfEdit2 2.0.4 Source
/
HexIO.p
< prev
next >
Wrap
Text File
|
1993-09-19
|
1KB
|
64 lines
unit HexIO;
interface
type
HexIOResult = (hexioNoErr, hexioBadDigit);
function Hex (x: longint; n: integer): string;
function Num (s: string; procedure Fail (why: HexIOResult)): longint;
implementation
function Hex (x: longint; n: integer): string;
var
buf: string[8];
i, d: integer;
c: char;
begin
buf := ' ';
for i := 0 to n - 1 do begin
d := BAND(x, $F);
x := BSR(x, 4);
if d < 10 then
c := chr(ord('0') + d)
else
c := chr(ord('A') + d - 10);
buf[8 - i] := c;
end;
Hex := copy(buf, 9 - n, n);
end;
function Num (s: string; procedure Fail (why: HexIOResult)): longint;
var
p, base: integer;
c: char;
n: longint;
begin
base := 10;
if (length(s) > 0) & (s[1] = '$') then begin
base := 16;
delete(s, 1, 1);
end;
n := 0;
p := 1;
while p <= length(s) do begin
n := n * base;
c := s[p];
p := p + 1;
case c of
'0'..'9':
n := n + ord(c) - ord('0');
'A'..'F':
n := n + ord(c) - ord('A') + 10;
'a'..'f':
n := n + ord(c) - ord('a') + 10;
otherwise
Fail(hexioBadDigit);
end;
end;
Num := n;
end;
end.